<template>
    <div id="background">
        <el-container>
            <el-header id="wpHeadPosition" style="position:fixed;top:0px;width:100%;z-index:2">
                <div id="weiPeiHead">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                    <el-col :xs="2" :sm="2" :md="2" :offset="1" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back" />
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol">
                        <span class="titleSize">定向委培</span>
                    </el-col>
                </el-row>
                </div>
                <div id="shaiXuanBar" style="backgroundColor:#ffffff">
                <el-row class="souSuoRow" type="flex">
                    <el-col style="width:25%;"  class="imgCol">
                        <span style="font-size:15px;">杭州</span>
                    </el-col>
                    <el-col style="width:25%;" class="imgCol">
                        <span v-show="!zuiXin" style="font-size:15px;" @click="changeZuiXin">
                            最新发布
                        </span>
                        <span v-show="zuiXin" style="font-size:15px;color:#53cdf5">
                            最新发布
                        </span>
                    </el-col>
                    <el-col style="width:25%;" class="imgCol">
                        <span v-show="!zuiGao" style="font-size:15px;"  @click="changeZuiGao">
                            工资最高
                        </span>
                        <span v-show="zuiGao" style="font-size:15px;color:#53cdf5">
                            工资最高
                        </span>
                    </el-col>
                    <el-col style="width:25%;" class="imgCol">
                        <span>
                            <img :src="shaiXuan" class="shaiXuan" @click="shaiXuanShow = true">
                        </span>
                        <span style="font-size:15px;margin-left:5px;" @click="shaiXuanShow = true">
                            条件
                        </span>
                        <van-popup 
                            v-model="shaiXuanShow" 
                            position="right" 
                            :style="{ width: '73%',height:'100%' }"
                        >
                            <div style="margin-top:20px">
                                <div style="margin-left:10px;margin-bottom:10px">
                                    <span class="words">工种选择</span>
                                </div>
                                <span v-for="(gongZhong,index) in gongZhongs" v-bind:key="gongZhong.professionId" >
                                    <button v-show="!mapGongZhong[index]" class="btnShaiXuan" @click="chooseGongZhong(index)">{{gongZhong.professionName}}</button>
                                    <button v-show="mapGongZhong[index]" class="btnShaiXuanChoose" @click="chooseGongZhong(index)">{{gongZhong.professionName}}</button>
                                </span>
                            </div>
                            <div style="margin-top:20px">
                                <div style="margin-left:10px;margin-bottom:10px">
                                    <span class="words">学历条件</span>
                                </div>
                                <span v-for="(xueLi,index) in xueLis" v-bind:key="index" >
                                    <button v-show="!arrXueLi[index]" class="btnShaiXuan" @click="chooseXueLi(index)">{{xueLi}}</button>
                                    <button v-show="arrXueLi[index]" class="btnShaiXuanChoose" @click="chooseXueLi(index)">{{xueLi}}</button>
                                </span>
                            </div>
                            <div style="margin-top:20px">
                                <div style="margin-left:10px;margin-bottom:10px">
                                    <span class="words">经验条件</span>
                                </div>
                                <span  v-for="(jinYan,index) in jinYans" v-bind:key="jinYan.id">
                                    <button v-show="!arrJinYan[index]" class="btnShaiXuan" @click="chooseJinYan(index)">{{jinYan.name}}</button>
                                    <button v-show="arrJinYan[index]" class="btnShaiXuanChoose" @click="chooseJinYan(index)">{{jinYan.name}}</button>
                                </span>
                            </div>
                            <div style="margin-top:20px">
                                <div style="margin-left:10px;margin-bottom:10px">
                                    <span class="words">性别条件</span>
                                </div>
                                <span  v-for="(sex,index) in sexs" v-bind:key="sex.id">
                                    <button v-show="!arrSex[index]" class="btnShaiXuan" @click="chooseSex(index)">{{sex.name}}</button>
                                    <button v-show="arrSex[index]" class="btnShaiXuanChoose" @click="chooseSex(index)">{{sex.name}}</button>
                                </span>
                            </div>
                            <div style="position:fixed;bottom:10px;width:100%">
                                <el-row >          
                                    <el-col :xs="12" :sm="12" :md="12" class="end">
                                        <button class="btnShaiXuanReset" @click="shaiXuanReset">重置</button>
                                    </el-col>
                                    <el-col :xs="12" :sm="12" :md="12">
                                        <button class="btnShaiXuanSure" @click="shaiXuanSure">确定</button>
                                    </el-col>
                                </el-row>
                            </div>
                        </van-popup>
                    </el-col>
                </el-row>
                </div>
            </el-header>
            <el-main id="weiPeiMain" style="padding:0;margin-top:130px;backgroundColor:#ffffff">
                <div style="height:5px;backgroundColor:#f5f4f9"></div>
                <el-row v-for="(value,key) in wpItems" :key="key"  v-infinite-scroll="load" infinite-scroll-disabled="disabled">

                    <div @click="goToWpxq(value.consignId)">
                    <el-row style="padding:10px 10px 6px 10px;backgroundColor:#ffffff;">
                        <el-container>
                            <el-aside style="width:90px;">
                                <el-image :src="value.consignPicture" style="width:80px;height:80px;" fit="cover"></el-image>
                            </el-aside>
                            <el-main style="padding:0;">
                                <el-row style="color:#707070;">
                                    <el-col :xs="15" :sm="15" :md="15" class="noHuanHang">
                                        <span >{{value.companyName}}</span>
                                    </el-col>
                                    <el-col :xs="8" :sm="8" :md="8" >
                                        <span >{{value.positionName}}</span>
                                    </el-col>
                                </el-row>
                                <el-row style="margin-top:8px;">
                                    <el-col :xs="16" :sm="16" :md="16" style="height:100%;">
                                       <van-tag color="#53cdf5" plain > <span style="color:#53cdf5;font-size:12px;">{{value.ageRequest}}</span></van-tag>
                                        <van-tag color="#f2826a" plain ><span style="color:#f2826a;font-size:12px;">{{value.socialSecurity}}</span></van-tag>
                                    </el-col>
                                    <el-col :xs="3" :sm="3" :md="3" :offset="3" class="noHuanHang" style="height:100%">
                                        <span style="color:#707070;">{{value.area}}</span>
                                    </el-col>
                                </el-row>
                                <el-row style="margin-top:8px;">
                                    <el-col :xs="15" :sm="15" :md="15">
                                       <span style="color:#f16161;" >
                                            {{value.salary}}
                                        </span>
                                    </el-col>
                                    <el-col  :xs="2" :sm="2" :md="2" :offset="4">
                                        <i class="el-icon-user-solid" style="font-size:12px;color:#707070"></i>
                                    </el-col>
                                    <el-col  :xs="3" :sm="3" :md="3" >
                                        <span style="font-size:12px;" class="words">{{value.countPopulation}}</span>
                                    </el-col>
                                </el-row>
                            </el-main>
                        </el-container>
                    </el-row>
                    </div>
                    <div style="height:5px;backgroundColor:#f5f4f9"></div>
                </el-row>
                    <div style="height:5px;backgroundColor:#fff"></div>
                    <div v-if="loading" class="imgCol">
                        <span class="words" style="font-size:14px">加载中...</span>
                    </div>
                    <div v-if="noMore" class="imgCol">
                        <span class="words" style="font-size:14px">没有更多了...</span>
                    </div>
                    <div style="height:10px"></div>
            </el-main>
        </el-container>
    </div>
</template>

<script>
import { Toast } from 'vant'
import { Popup } from 'vant'
import weiPei from '../../assets/img/weiPei/weiPei.png'
import shaiXuan from '../../assets/img/weiPei/shaiXuan.png'
import backIcon from '../../assets/img/mine/back.png'
export default {
    data(){
        return{
             //绑定加载状态是否显示
            loading: false,
            noGengDuo:false,
            //绑定性别信息
            sexs:[{id:null,name:'不限'},{id:true,name:'男'},{id:false,name:'女'}],
            //绑定性别的选择与否
            arrSex:[1,0,0],
            //绑定经验信息
            jinYans:[{id:1,name:'不限'},{id:2,name:'一年以下'},{id:3,name:'1~3年'},{id:4,name:'3年以上'}],
            //绑定经验的选择与否
            arrJinYan:[1,0,0,0],
            //绑定学历信息
            xueLis:[{id:1,name:'本科'},{id:2,name:'高中'},{id:3,name:'初中'},{id:4,name:'大专'},{id:5,name:'小学'},{id:6,name:'幼稚园'}],
            //绑定学历的选择与否
            arrXueLi:[],
             //绑定工种信息
            gongZhongs:[],
            //绑定工种的选择与否
            mapGongZhong:[],
            shaiXuanShow:false,
            zuiXin:true,
            zuiGao:false,
            orderType:'NEW',
            pageNo:1,
            pageSize:6,
            total:0,
            wpItems:[],
            shaiXuan:shaiXuan,
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
        }
    },
    computed: {
      noMore () {
        return this.wpItems.length>=this.total;
      },
      disabled () {
        return this.loading || this.noMore;
      }
    },
    mounted(){
        
        
        window.addEventListener('scroll', this.handleScroll);

        var bg = document.getElementById("background");
        console.log("height:"+this.normalHeight);
        bg.style.height = this.normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

        // var wphead=document.getElementById("wpHeadPosition");
        // var wpheadHeight=this.normalHeight/30 *6 ;
        // console.log("wpheadHeight:"+wpheadHeight);
        // wphead.style.height=wpheadHeight+"px";

        var head=document.getElementById("weiPeiHead");
        var headHeight=this.normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        // var sxBar=document.getElementById("shaiXuanBar");
        // var sxBarHeight=this.normalHeight/30 *2 ;
        // console.log("sxBarHeight:"+sxBarHeight);
        // sxBar.style.height=sxBarHeight+"px";

        // var main=document.getElementById("weiPeiMain");
        // var mainHeight=this.normalHeight/30 *24 ;
        // main.style.height=mainHeight+"px";

        // this.getweiPei();
        this.getZhiYes();
        this.getXueLis();
        var params='';
        this.pageNo=1;
        params={
            pageNo:this.pageNo,
            pageSize:this.pageSize,
            orderType:'NEW',
            // companyCity:'杭州'
        }
        var data={
            	// province: null,
                companyCity: null,
                // area: null,
                professionId: 1,
                // positionId: null,
                sexRequest:null,
                minAgeRequest: null,
                maxAgeRequest: null,
                educationBackground: null,
                minExpRequest: null,
                maxExpRequest: null,
        }
        this.getweiPei(params,data);
    },
    methods:{
        load () {
            this.loading = true
            setTimeout(() => {
                var params={};
                this.pageNo++;
                // params={
                //         pageNo:this.pageNo,
                //         pageSize:5,
                //         orderType:'NEW',
                //         companyCity:'杭州'
                //     }
                // this.getweiPei(params);
                params={
                        pageNo:this.pageNo,
                        pageSize:this.pageSize,
                        orderType:'NEW',
                        // companyCity:'杭州'
                    }
                var data={
                     companyCity: null,
                // area: null,
                professionId: null,
                // positionId: null,
                sexRequest:null,
                minAgeRequest: null,
                maxAgeRequest: null,
                educationBackground: null,
                minExpRequest: null,
                maxExpRequest: null,
                }
                this.getweiPei(params,data);
                this.loading = false;

            }, 2000)
        },
        //提交筛选结果(这里未处理经验筛选，优化过后再改进)
      shaiXuanSure(){
          if(this.zuiXin==true){
              var type='NEW';
          }else{
              var type='SALARY'
          }
          //处理学历
          var index1=0,xueLi='';
          index1=this.arrXueLi.indexOf(1);
          console.log(index1);
          if(index1<0){
              xueLi=null;
          }else{
              xueLi=this.xueLis[index1];
          }
          var index2=0,sex='';
          index2=this.arrSex.indexOf(1);
          console.log(index2)
          if(index2<0){
              sex=null;
          }else{
              sex=this.sexs[index2].id;
          }
          var index3=0,gongZhong=null;
          index3=this.mapGongZhong.indexOf(1);
          console.log(index3);
          if(index3<0){
              index3='';
          }else{
              gongZhong=this.gongZhongs[index3].professionId;
          }
          this.pageNo=1;
          var params={
              pageSize:this.pageSize,
              pageNo:this.pageNo,
              orderType:type,
            //   companyCity:'杭州',
            //   educationBackground:xueLi,
            //   sexRequest:sex,
            //   professionId:gongZhong
          }
          var data={
            	// province: null,
                companyCity: null,
                // area: null,
                professionId: gongZhong,
                // positionId: null,
                sexRequest:sex,
                minAgeRequest: null,
                maxAgeRequest: null,
                educationBackground: xueLi,
                minExpRequest: null,
                maxExpRequest: null,
        }
          this.wpItems=[];
        //   this.pageNo=1;
          console.log(params);
          console.log(data);
          this.getweiPei(params,data);
          Toast("筛选成功！");
          this.shaiXuanShow=false;
      },
        //重置条件筛选
      shaiXuanReset(){
        this.chooseGongZhong(-1);
        this.chooseXueLi(-1);
        this.chooseJinYan(-1);
        this.chooseSex(-1);
      },
        //变化性别
      chooseSex(index){
          var i=0;
          for(i=0;i<this.arrSex.length;i++){
              this.$set(this.arrSex,i,0);
          }
          if(index!=-1){
            this.$set(this.arrSex,index,1);
          }else{
              this.$set(this.arrSex,0,1);
          }

      },
         //变化经验
      chooseJinYan(index){
          var i=0;
          for(i=0;i<this.arrJinYan.length;i++){
              this.$set(this.arrJinYan,i,0);
          }
          if(index!=-1){
            this.$set(this.arrJinYan,index,1);
          }else{
              this.$set(this.arrJinYan,0,1);
          }

          console.log(this.arrJinYan);
      },
        //变化学历
      chooseXueLi(index){
          console.log(index);
          var i=0;
          for(i=0;i<this.arrXueLi.length;i++){
              this.$set(this.arrXueLi,i,0);
          }
          if(index!=-1){
            this.$set(this.arrXueLi,index,1);
          }
          console.log(this.arrXueLi);
      },
        //获取学历条件
      getXueLis(){
            var URL=this.IP.IP+'/post/eduEnum';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.xueLis=response.data.data;
                    var i=0;
                    for(i=0;i<this.xueLis.length;i++){
                        this.arrXueLi[i]=0;
                    }
                    // console.log(this.mapXueLi);
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
      },
        //条件筛选变化工种,map实现双向绑定
      chooseGongZhong(index){
            console.log(index);
            var i=0;
            for(i=0;i<this.mapGongZhong.length;i++){
                this.$set(this.mapGongZhong,i,0);
            }
            if(index!=-1){
                this.$set(this.mapGongZhong,index,1);
            }
      },
        //获取工种种类
        getZhiYes(){
            var URL=this.IP.IP+'/visitor/getProfessionInformation';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.gongZhongs=response.data.data.professionInformation;
                    var i=0;
                    for(i=0;i<this.gongZhongs.length;i++){
                        this.mapGongZhong[i]=false;
                    }
                    // this.gongZhongs[0]['choose']=true;
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
      },
        changeZuiGao(){
                this.zuiXin=false;
                this.zuiGao=true;
                this.wpItems=[];
                this.pageNo=1;
                var params='';
                params={
                    pageNo:this.pageNo,
                    pageSize:this.pageSize,
                    orderType:'SALARY',
                    // companyCity:'杭州'
                }
                var data={
                        // province: null,
                        companyCity: null,
                        // area: null,
                        professionId: 1,
                        // positionId: null,
                        sexRequest:null,
                        minAgeRequest: null,
                        maxAgeRequest: null,
                        educationBackground: null,
                        minExpRequest: null,
                        maxExpRequest: null,
                }
                this.getweiPei(params,data);
        },
        changeZuiXin(){
                this.zuiXin=true;
                this.zuiGao=false;
                this.wpItems=[];
                this.pageNo=1;
                var params='';
                params={
                    pageNo:this.pageNo,
                    pageSize:thia.pageSize,
                    orderType:'NEW',
                    // companyCity:'杭州'
                }
                var data={
                        // province: null,
                        companyCity: null,
                        // area: null,
                        professionId: 1,
                        // positionId: null,
                        sexRequest:null,
                        minAgeRequest: null,
                        maxAgeRequest: null,
                        educationBackground: null,
                        minExpRequest: null,
                        maxExpRequest: null,
                }
                this.getweiPei(params,data);
        },
        getweiPei(params,data){
            var URL=this.IP.IP+'/consign/consignSatisfyTheConditionsOf';
             console.log(URL);
            console.log(params);
            console.log(data);
            this.$ajax({
                    method:'post',
                    url:URL,
                    data:data,
                    params: params
                }).then(response =>{
                // this.wpItems=response.data.data.info;
                    var code=0;
                    code=response.data.code;
                    if(code==0){
                                var i=0;
                                for(i=0;i<response.data.data.info.length;i++){
                                    this.wpItems.push(response.data.data.info[i]);
                                };
                                this.total=response.data.data.total;
                                console.log(response.data);
                    }else{
                       // Toast(response.data.msg);
                    }
        
                }).catch(error => {
                console.log('委培信息获取失败');
                });
        },
        goToWpxq(consignId){
            console.log('这里是Id'+consignId);
            this.$router.push({
                path:'/weiPei/weiPeiXiangQing',
                query:{
                    consignId:consignId
                },
                
            })
        },
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
    }
}
</script>

<style>
.words{
    color:#909090;
}
.noHuanHang{
    white-space: nowrap;
    overflow: hidden;
}
.end{
    display: flex;
    justify-content: flex-end;
}
.btnShaiXuanReset{
    background-color: #fff;
    height: 40px;
    width: 80%;
    color: #53cdf5;
    font-size: 1.125em;
    outline: none;
    /* border-radius: 0px; */
    border-top-left-radius: 25px;
    border-bottom-left-radius: 25px;
    border:#53cdf5 1px solid;
}
.btnShaiXuanSure{
    background-color: #53cdf5;
    height: 40px;
    width: 80%;
    color: #ffffff;
    font-size: 1.125em;
    outline: none;
    /* border-radius: 0px; */
    border-top-right-radius: 25px;
    border-bottom-right-radius: 25px;
    border:#53cdf5 1px solid;
}
.btnShaiXuanChoose{
    border-style: none;
    height: 30px;
    /* width: 60px; */
    width: 25%;
    background-color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    font-size: 13px;
    color: #53cdf5;
    border:1px solid #53cdf5;
    margin-bottom: 10px;
    margin-left:10px;
    border-radius: 5px;
}
.btnShaiXuan{
    border-style: none;
    height: 30px;
    /* width: 60px; */
    width: 25%;
    background-color: #E0E0E0;
    white-space: nowrap;
    overflow: hidden;
    font-size: 13px;
    margin-bottom: 10px;
    margin-left:10px;
    border-radius: 5px;
}
.words{
    color:#707070;
}
.dxline{
    width: 100%;
    height: 2px;
    background-color: #F0F0F0;
}
.dxBigLine{
    width: 100%;
    height: 5px;
    background-color: #F0F0F0;
}
.chengShixz .el-input__inner {
    border: none;
    border-color: #F0F0F0;
    background-color: rgba(255, 255, 255, 0);
    color: #707070;
    border-radius: 0px;
    padding: 0;

}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
.souSuoRow{
    padding:10px;
    color: #707070;
    height:100%;
}
.shaiXuan{
    width:18px;
    height:12px;
}
.el-header{
    padding:0;
}
#weiPeiHead {
  background-color: #53cdf5;
}
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
}
</style>